home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / mkversion / mkversion.c < prev    next >
C/C++ Source or Header  |  1988-11-13  |  2KB  |  89 lines

  1. /* 
  2.  * mkversion.c --
  3.  *
  4.  *    Output a string to be used as "version.h" describing the current
  5.  *    working directory and date/time.
  6.  *
  7.  * Copyright 1987 Regents of the University of California
  8.  * All rights reserved.
  9.  */
  10.  
  11. #ifndef lint
  12. static char rcsid[] = "$Header: /a/newcmds/mkversion/RCS/mkversion.c,v 1.4 88/11/13 12:02:47 brent Exp $ SPRITE (Berkeley)";
  13. #endif not lint
  14.  
  15. #include "stdio.h"
  16. #include "sys/param.h"
  17. #include "sys/time.h"
  18. #include "time.h"
  19. #include "option.h"
  20.  
  21. int printDir = 0;
  22. int printDate = 1;
  23. char *prog = NULL;
  24.  
  25. Option optionArray[] = {
  26.     {OPT_TRUE, "d",  (char *) &printDir,
  27.     "Print the current working directory (TRUE)"},
  28.     {OPT_FALSE, "t",  (char *) &printDate,
  29.     "Don't print the date/time-stamp (FALSE)"},
  30.     {OPT_STRING, "p",  (char *) &prog,
  31.     "Output program name STRING (following the directory, if applicable)"},
  32. };
  33. int numOptions = sizeof(optionArray) / sizeof(Option);
  34.  
  35. main(argc, argv)
  36.     int        argc;
  37.     char    *argv[];
  38. {
  39.     struct    timeval    curTime;
  40.     struct    timezone    local;
  41.     char     pathName[MAXPATHLEN];
  42.  
  43.     (void) Opt_Parse(argc, argv, optionArray, numOptions, OPT_ALLOW_CLUSTERING);
  44.  
  45.     printf("#define VERSION \"");
  46.     
  47.     if (printDir) {
  48.     if (getwd(pathName) == NULL) {
  49.         fprintf(stderr, "Error in getwd: '%s'\n", pathName);
  50.     } else {
  51.         printf("%s", pathName);
  52.     }
  53.     }
  54.     if (prog) {
  55.     if (printDir) {
  56.         printf("/");
  57.     }
  58.     printf("%s", prog);
  59.     }
  60.     if (printDir || prog) {
  61.     printf(" ");
  62.     }
  63.     if (printDate) {
  64.     char *date;
  65.     int numDateChars = 1;
  66.     extern char *asctime();
  67.  
  68.     gettimeofday(&curTime, &local);
  69.     date = asctime(localtime(&curTime.tv_sec));
  70.     /*
  71.      *  ctime format is ugly:
  72.      *  "Sat Aug 10 10:30:01 1987\n\0"
  73.      *   012345678901234567890123 4 5
  74.      *
  75.      * Make it look like Time_ToAscii by picking substrings.
  76.      * Get rid of the leading space in the date by checking for ' '
  77.      * and printing 1 or 2 chars, starting at the first non-blank.
  78.      */
  79.  
  80.     if (date[8] != ' ') {
  81.         numDateChars++;
  82.     }
  83.     printf("(%.*s %.3s %.2s %.8s)", numDateChars,
  84.          &date[10-numDateChars], &date[4], &date[22], &date[11]);
  85.     }
  86.     printf("\"\n");
  87.     exit(0);
  88. }
  89.